#include <stdio.h>
#include <string.h>
struct stu
{
	char id[20];
	char name[20];
	float score;
};
int main(int argc,const char*argv[])
{
	FILE*p=NULL;
	if((p=fopen(argv[1],"a"))==NULL){perror("打开错误：");return -1;}
	struct stu a[3]={{"1003","张三",90.2},
					 {"1004","李四",90.4},
					 {"1005","王五",90.6}};
	size_t ret=fwrite(a,sizeof(struct stu),3,p);
	if(ret!=3){perror("写入错误：");return -1;}
	fclose(p);
	p=NULL;
	if((p=fopen(argv[1],"r"))==NULL){perror("打开错误：");return -1;}
	struct stu b[3]={0};
	ret=fread(b,sizeof(struct stu),3,p);
	if(ret!=3){perror("读取错误：");return -1;}
	for(int i=0;i<3;i++)
		printf("%s  %s  %f\n",b[i].id,b[i].name,b[i].score);
	fclose(p);
	return 0;
}
